﻿#region Imports
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using CommonUtilities.Extensions;
#endregion

namespace DirectoryAnalyzer.Controls
{
    /// <summary>
    /// Interaction logic for ExpanderSimple.xaml
    /// </summary>
    public partial class ExpanderSimple : System.Windows.Controls.UserControl
    {
        private string toggleButtonText;
        public string ToggleButtonText
        {
            get { return txtbHeader.Text; }
            set { txtbHeader.Text = value; }
        }

        private bool hasThreeState = false;
        public bool HasThreeState
        {
            get { return hasThreeState; }
            set { hasThreeState = value; }
        }

        public bool? IsChecked
        {
            get { return chkSilent.IsChecked; }
            set
            {
                chkSilent.IsChecked = value;

                switch (chkSilent.IsChecked.GetCheckState())
                {
                    case CheckState.Checked:
                        ToggleButtonText = TextTrue;
                        expExpander.IsExpanded = true;
                        expExpander.ExpandDirection = ExpandDirection.Down;
                        break;

                    case CheckState.Unchecked:
                        ToggleButtonText = TextFalse;
                        expExpander.IsExpanded = false;
                        expExpander.ExpandDirection = ExpandDirection.Left;
                        break;

                    case CheckState.Indeterminate:
                    default:
                        ToggleButtonText = HasThreeState ? TextMixed : TextFalse;
                        expExpander.IsExpanded = false;
                        expExpander.ExpandDirection = ExpandDirection.Down;
                        break;
                }
            }
        }

        public static string textTrue = "True -> False";
        /// <summary>
        /// Text to display when 'toggle' value is 'true'
        /// <para>Hint: Directs user to select button to perform actions to make it 'false'</para>
        /// </summary>
        public string TextTrue
        {
            get { return textTrue; }
            set { textTrue = value; /*RaisePropertyChanged("TextTrue");*/ }
        }

        public static string textFalse = "False -> True";
        /// <summary>
        /// Text to display when 'toggle' value is 'false'
        /// <para>Hint: Directs user to select button to perform actions to make it 'true'</para>
        /// </summary>
        public string TextFalse
        {
            get { return textFalse; }
            set { textFalse = value; /*RaisePropertyChanged("TextFalse");*/ }
        }

        private string textMixed = "Mixed (null)";
        public string TextMixed
        {
            get { return textMixed; }
            set { textMixed = value; }
        }

        public ExpanderSimple()
        {
            InitializeComponent();
        }

        int sum = 0;
        private void expExpander_MouseDown(object sender, MouseButtonEventArgs e)
        {
            sum = -1;
        }

        private void expExpander_MouseUp(object sender, MouseButtonEventArgs e)
        {
            sum += 1;
            if (sum == 0) IsChecked = !IsChecked.GetValueOrDefault(false);
            //{
            //    if (HasThreeState)
            //        IsChecked = !IsChecked.GetValueOrDefault(false);
            //    else IsChecked = !IsChecked;
            //}
        }
    }
}
